package com.gc.controller;

import com.gc.common.resp.ApiResult;
import com.gc.pojo.SysDevice;
import com.gc.services.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;


@Controller
@RequestMapping("device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @GetMapping("add-view")
    public ModelAndView addView(){
        ModelAndView mav = new ModelAndView("device/add");
        return mav;
    }

    @GetMapping("getAll")
    @ResponseBody
    public List<SysDevice> getAll(){
        return deviceService.getAllDevice();
    }
    @PostMapping("remove")
    @ResponseBody
    public ApiResult remove(@RequestParam Integer deviceId){
        int remove = deviceService.remove(deviceId);
        return new ApiResult();
    }
    @PostMapping("add")
    @ResponseBody
    public ApiResult add(@RequestBody SysDevice device){
        device.setCreateTime(new Date());
        int remove = deviceService.addDevice(device);
        return new ApiResult();
    }

    @PostMapping("modify")
    @ResponseBody
    public ApiResult modify(@RequestBody SysDevice device){
        int count = deviceService.modifyDevice(device);
        return new ApiResult();
    }

    @GetMapping("get")
    @ResponseBody
    public SysDevice get(@RequestParam Integer deviceId){
        SysDevice device = deviceService.getDeviceById(deviceId);
        return device;
    }




}
